package com.liyue.valueutil;

import android.content.Context;
import android.util.DisplayMetrics;

public class MathUtil {


    /**
     * 十进制转十六进制
     *
     * @param a 十进制int类型
     * @return 十六进制字符串
     */

    public static String Math10to16(int a) {
        int n = a;
        char[] ch = new char[20];
        int index = 0;
        while (true) {
            int m = n / 16;
            int y = n % 16;
            if (y == 15) {
                ch[index] = 'F';
            } else if (y == 14) {
                ch[index] = 'E';
            } else if (y == 13) {
                ch[index] = 'D';
            } else if (y == 12) {
                ch[index] = 'C';
            } else if (y == 11) {
                ch[index] = 'B';
            } else if (y == 10) {
                ch[index] = 'A';
            } else {
                ch[index] = (char) ('0' + y);
            }
            index++;
            if (m == 0) {
                break;
            }
            n = m;
        }
        StringBuffer s = new StringBuffer();
        s.append(ch, 0, index);
        s.reverse();
        String strHex = "0x";
        strHex += s.toString();
        return strHex;
    }
}
